package com.xuecheng.content.controller;

import com.xuecheng.api.conttent.CourseBaseApi;
import com.xuecheng.api.conttent.mordle.dto.CourseBaseDTO;
import com.xuecheng.api.conttent.mordle.po.QueryCourseModel;
import com.xuecheng.api.conttent.mordle.vo.CourseBaseVo;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.CourseBaseConvert;
import com.xuecheng.content.entity.CourseBase;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.content.service.CourseBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 课程基本信息 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
@RequestMapping
public class CourseBaseController implements CourseBaseApi {

    @Autowired
    private CourseBaseService  courseBaseService;

    /**
     * @param params 分页请求参数，内含pageNo（当前页），pageSize（每页查询条数）
     * @param model 条件查询请求体，内含auditStatus（课程审核状态），courseName（课程名称）
     * @return
     */
    @Override
    @PostMapping("/course/list")
    public PageVO<CourseBaseDTO> queryCourseList(PageRequestParams params, @RequestBody QueryCourseModel model) {
        //拿到请求头并解析公司id
        Long companyId = SecurityUtil.getCompanyId();
        return courseBaseService.queryCourseList(params, model,companyId);
    }



    /**
    *@Param [dto]
    *@Return CourseBaseDTO
    *@Description
    *@author lenovo
    *@Date 22:32
    **/


    @Override
    public CourseBaseDTO modifyCourseBase(@RequestBody CourseBaseVo vo) {
        CourseBaseDTO dto = CourseBaseConvert.INSTANCE.vo2dto(vo);
        Long companyId = SecurityUtil.getCompanyId();
        dto.setCompanyId(companyId);
        return courseBaseService.createCourseBase(dto);
    }

}
